package biz.ezcom.spring.ioc.service;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;

import biz.ezcom.spring.ioc.dao.UserDao;

public class UserService {
	
	private UserDao userDao;
	
	public UserDao getUserDao() {
		return userDao;
	}
	
//	@Autowired //byType自动装配,等于：@Autowired(required=true)：表示此属性必须装配(ioc容器中必需只有一个UserDao类型的对象)
//	public void setUserDao(UserDao userDao) {
//		this.userDao = userDao;
//	}
	
//	@Autowired(required=false) //byType自动装配,ioc容器有就装配进来，没有userDao = null
//	public void setUserDao(UserDao userDao) {
//		this.userDao = userDao;
//	}
	
	@Autowired //与@Qualifier一起使用：表示按byName装配
	public void setUserDao(@Qualifier(value="userDaoName") UserDao userDao) {
		this.userDao = userDao;
	}
	
	public void saveUser() {
		if(userDao != null){
			userDao.saveUser();
		}
	}
}
